DSFX.Color = function( colorString )
{	
	this.ok = false;
	return this.match( colorString || "#000" );
};
	
DSFX.Color.prototype = 
{	
	engines: 
	{
	    rgb: 
	    {
	        regexp: /^rgb\((\d{1,3}),\s*(\d{1,3}),\s*(\d{1,3})\)$/,
	        process: function( bit ) {  return parseInt( bit ); }
	    },
	    
	    fullHex: 
	    {
	        regexp: /^(\w{2})(\w{2})(\w{2})$/,
	        process: function( bit ) {  return parseInt( bit, 16 ); }     
	    },
	    
	    halfHex: 
	    {
	        regexp: /^(\w{1})(\w{1})(\w{1})$/,
	        process: function( bit ) {  return parseInt( bit + bit, 16 ); }
	    }
	},
	
	colorPart: function( number )
	{
		var hex = number.toString( 16 );
		return hex.length == 1 ? '0' + hex : hex;
	},
	
	match: function( colorString )
	{
		if ( !colorString.charAt || colorString == "" )
		{
			return;
		}
		if ( colorString.charAt( 0 ) == "#" )
		{
			colorString = colorString.substr( 1, 6 );
		}
		colorString = colorString.replace( / /, "" ).toLowerCase();
		for ( var slot in this.engines )
		{
			var engine = this.engines[ slot ];
			var bits = engine.regexp.exec( colorString );
			if ( bits )
			{
				for ( var ii = 1, len2 = bits.length; ii < len2; ii++ )
				{
					this[ "rgb".split('')[ ii - 1 ] ] = engine.process( bits[ii] );
				}
				this.ok = true;
			}
		}
		return this;
	},
	
	rgb: function()
	{
		return 'rgb(' + this.r + ', ' + this.g + ', ' + this.b + ')';
	},
	
	hex: function()
	{
		return '#' + this.colorPart( this.r ) + this.colorPart( this.g ) + this.colorPart( this.b );
	},
    
    invert: function() 
    {
    	this.r = 255 - this.r;
    	this.g = 255 - this.g;
    	this.b = 255 - this.b;
    	return this;
    }
};
